<?php
/**
 * @Title: confv
 * @Description: todo(获取配置值)
 * @param string $k
 * @param string $type
 * @return string
 * @author 若谷
 * @date 2019年1月1日
 * @throws
 */
function confv($k, $type = 'web'){
    $config = new app\common\model\Config;
    return $config->confv($k, $type);
}

/**
 * @Title: getAccessToken
 * @Description: todo(获取微信access_token)
 * @return string
 * @author 若谷
 * @date 2019年1月1日
 * @throws
 */
function getAccessToken(){
	$model = new app\common\model\AccessToken;
	$data = $model->get(1);
	$time = time();
	if ($time>$expire_time) {
		$appid  = confv('wx_appid');
	    $secret = confv('wx_secret');
	    $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$secret;
	    $result = httpRequest($url);
	    $result = json_decode($result,1);
	    $msg = [
	    	'id' => 1,
	    	'access_token' => $result['access_token'],
	    	'expire_time'  => $time+7000,
	    ];
	    $model->allowField(true)->save($msg, $msg['id']);
	    return $result['access_token'];
	}
	return $data['access_token'];
}

